package com.soft.javase.day11.serial;

import java.io.*;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/9
 */
public class User implements /*Serializable*/ Externalizable {
    private static final long serialVersionUID = 1L;

    private String name;
    private int age;

    private String password;

    private static int count;
    private transient String address;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", address='" + address + '\'' +
                ", count=" + count +
                ", password='" + password + '\'' +
                '}';
    }

    @Override
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeObject(name);
        out.writeObject(age);
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
       this.name = (String) in.readObject();
       this.age = (Integer) in.readObject();
    }
}
